﻿using System.Data;
using System.Data.OleDb;

namespace CalculoPreciosUnitarios.Logica.GestorObject.LectorExcel
{
    public class LectorExcelCS
    {
        /** Arch: Ruta del archivo
         *  Hoja: Nombre de la hoja donde estan los datos en Excel
         **/

        public static DataTable SelectExcel(string Arch, string Hoja)
        {

            OleDbConnection Conex = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Arch + ";Extended Properties=Excel 12.0;");

            OleDbCommand CmdOle = new OleDbCommand();

            CmdOle.Connection = Conex;
            CmdOle.CommandType = CommandType.Text;
            CmdOle.CommandText = "SELECT * FROM [" + Hoja + "$]";

            OleDbDataAdapter AdaptadorOle = new OleDbDataAdapter(CmdOle.CommandText, Conex);

            DataTable dt = new DataTable();

            AdaptadorOle.Fill(dt);

            return dt;
        }
    }
}
